package com.tmc.dao.impl.intair;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

import com.tmc.bean.common.ContextInfo;
import com.tmc.bean.common.Pagination;
import com.tmc.bean.common.TripartiteReport;
import com.tmc.dao.impl.BaseDaoImpl;
import com.tmc.entity.intair.IntairFare;
import com.tmc.entity.intair.IntairOrder;
import com.tmc.util.DateUtil;
import com.tmc.util.ObjectUtil;

@Repository
public class IntairFareDaoImpl extends BaseDaoImpl<IntairFare> {

	public Pagination<IntairFare> findByCon(ContextInfo context, IntairFare cond, int pageIndex, int pageSize) {
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		sql.append(" from  IntairFare  c  where c.enabledFlag = 'Y' ");
		sql.append(" order by c.lastUpdateDate desc ");
		return this.findPagination(sql.toString(), params, pageIndex, pageSize);
	}
	/**
	 * 分组查询报表
	 * 
	 * @param context
	 * @param fare
	 * @param order
	 * @param pageIndex
	 * @param pageSize
	 * @param groupByMap
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	 public Pagination<Map> findByFareAndOrder(ContextInfo context, IntairFare fare,
			IntairOrder order,int pageIndex, int pageSize, 
			Map<String,String> groupByMap) {
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		StringBuilder sqlCount = new StringBuilder();//计算分页的总记录数的SQL
		StringBuilder sqlNormal = new StringBuilder();//正常票SQL段
		StringBuilder sqlRefund = new StringBuilder();//退票SQL段
		StringBuilder sqlInvalid = new StringBuilder();//废票SQL段
		StringBuilder sqlCondition = new StringBuilder(); //条件SQL段
		
		StringBuilder sqlGroupBy = new StringBuilder(); //分组条件
		if(groupByMap == null || groupByMap.size() < 1 || groupByMap.isEmpty()){
			return new Pagination<>(pageIndex, pageSize, 0L);
		}
		for (Map.Entry<String, String> obj : groupByMap.entrySet()) {
				//判断是否为按月分组条件
			if(obj.getValue().equals("departureDate") || obj.getValue().equals("operatoringTime")){
				sqlGroupBy.append("truncate(f."+obj.getKey()+",-6) as "+obj.getValue()+",");
			}else{
				sqlGroupBy.append("f."+obj.getKey()+" as "+obj.getValue()+",");
			}
			
		}
		
		sqlNormal.append("select "+sqlGroupBy
				+ " count(1) as totalNormalTicket,"
				+ " sum(f.total_Amount) as totalAmount,"
				+ " sum(f.vendor_Total_Amount) as vendorTotalAmount,"
				+ " sum(f.ticket_Price) as totalTicketPrice,"
				+ " sum(f.tax) as totalTax "			
				+ " from fare_and_order f where f.enabled_Flag = 'Y' and f.ticket_status ='TICKET_STATUS_NORMAL' ");	
		sqlRefund.append("select "+sqlGroupBy
				+ " count(1) as totalRefundTicket,"
				+ " sum(f.refund_Price) as totalRefundPrice,"
				+ " sum(f.vendor_Refund_Price) as totalVendorRefundPrice"			
				+ " from fare_and_order f where f.enabled_Flag = 'Y' and f.ticket_status ='TICKET_STATUS_REFUND' ");
		sqlInvalid.append("select "+sqlGroupBy
				+ " count(1) as totalInvalidTicket,"
				+ " sum(f.refund_Price) as totalInvalidActualAmount,"
				+ " sum(f.abandon_Price) as totalAbandonPrice "				
				+ " from fare_and_order f where f.enabled_Flag = 'Y' and f.ticket_status ='TICKET_STATUS_INVALID' ");
		//筛选条件
		if(ObjectUtil.hasText(fare.getOperatoringTimeStartStr())){
			sqlCondition.append(" and f.operatoring_Time >= :operatoringTimeStart");
			params.put("operatoringTimeStart", DateUtil.toLongDate(fare.getOperatoringTimeStartStr(), DateUtil.yyyy_MM_dd));
		}
		if(ObjectUtil.hasText(fare.getOperatoringTimeEndStr())){
			sqlCondition.append(" and f.operatoring_Time <= :operatoringTimeEnd");
			params.put("operatoringTimeEnd", DateUtil.toLongDate(fare.getOperatoringTimeEndStr(), DateUtil.yyyy_MM_dd));
		}
		if(fare.getEshopId() != null){
			sqlCondition.append(" and f.eshop_Id =:eshopId ");
			params.put("eshopId", fare.getEshopId());			
		}
		if(ObjectUtil.hasText(order.getPlatform())){
			sqlCondition.append(" and f.platform = :platform ");
			params.put("platform", order.getPlatform());
		}
		if(ObjectUtil.hasText(order.getDepartureDateStartStr())){
			sqlCondition.append(" and f.departure_Date >= :departureDateStart");
			params.put("departureDateStart", DateUtil.toLongDate(order.getDepartureDateStartStr(), DateUtil.yyyy_MM_dd));					
		}
		if(ObjectUtil.hasText(order.getDepartureDateEndStr())){
			sqlCondition.append(" and f.departure_Date >= :departureDateEnd");
			params.put("departureDateEnd", DateUtil.toLongDate(order.getDepartureDateEndStr(), DateUtil.yyyy_MM_dd));
		}
		if(ObjectUtil.hasText(order.getAirline())){
			sqlCondition.append(" and f.airline =:airline");
			params.put("airline", order.getAirline());
		}
		if(ObjectUtil.hasText(order.getDepartureCity())){
			sqlCondition.append(" and f.departure_City =:departureCity");
			params.put("departureCity", order.getDepartureCity());
		}
		if(ObjectUtil.hasText(order.getArrivalCity())){
			sqlCondition.append(" and f.arrival_City =:arrivalCity");
			params.put("arrivalCity", order.getArrivalCity());
		}
		if(fare.getDrawOperatorId() != null){
			sqlCondition.append(" and f.draw_Operator_Id =:drawOperatorId");
			params.put("drawOperatorId", fare.getDrawOperatorId());
		}
		if(order.getBookOperatorId() != null){
			sqlCondition.append(" and f.book_Operator_Id =:bookOperatorId");
			params.put("bookOperatorId", order.getBookOperatorId());
		}
		//分组条件
		sqlCondition.append(" group by ");
		for(Map.Entry<String, String> obj : groupByMap.entrySet()){
			//判断是否为按月分组条件
			if(obj.getValue().equals("departureDate") || obj.getValue().equals("operatoringTime")){
				sqlCondition.append("truncate(f."+obj.getKey()+",-6),");
			}else{
				sqlCondition.append(" f."+obj.getKey()+",");
			}
			
		}	
		sqlCondition.append("f.ticket_status");
		
		sqlNormal.append(sqlCondition);
		sqlRefund.append(sqlCondition);
		sqlInvalid.append(sqlCondition); 
		//左连接查询的条件
		StringBuilder str1 = new StringBuilder();
		StringBuilder str2 = new StringBuilder();
		int flag = 1;//用来获取遍历map时的下标值的临时变量
		for (Map.Entry<String, String> entry : groupByMap.entrySet()) {
			if(groupByMap.size() <= 1){
				str1.append(" normal."+entry.getValue()+" = refund."+entry.getValue());
				str2.append(" normal."+entry.getValue()+" = invalid."+entry.getValue());
			}else{
				if(groupByMap.size() == flag){
					str1.append(" normal."+entry.getValue()+" = refund."+entry.getValue());
					str2.append(" normal."+entry.getValue()+" = invalid."+entry.getValue());
				}else{
					str1.append(" normal."+entry.getValue()+" = refund."+entry.getValue()+" and ");
					str2.append(" normal."+entry.getValue()+" = invalid."+entry.getValue()+" and ");
				}
			}
			flag++;
		}
		
		sql.append(" select normal.*,refund.totalRefundTicket,refund.totalRefundPrice,refund.totalVendorRefundPrice,"
				+ " invalid.totalInvalidTicket,invalid.totalInvalidActualAmount,invalid.totalAbandonPrice from "
				+ " ("+ sqlNormal + " ) as normal left join "
				+ " ("+ sqlRefund+" ) as refund on "+str1+" left join "
				+ " ("+ sqlInvalid+") as invalid on "+str2);
		
		sqlCount.append("select count(1) from ("+sql+") s"); //计算总记录数SQL	
		return this.findSqlPagination(sql.toString(), sqlCount, params, pageIndex, pageSize);
		
	}
	
	@SuppressWarnings("rawtypes")
	public List<Map> findByFareAndOrder(ContextInfo context, IntairFare fare, IntairOrder order) {
		
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		StringBuilder sqlNormal = new StringBuilder();//正常票SQL段
		StringBuilder sqlRefund = new StringBuilder();//退票SQL段
		StringBuilder sqlInvalid = new StringBuilder();//废票SQL段
		StringBuilder sqlCondition = new StringBuilder(); //条件SQL段
		
		sqlNormal.append("select f.airline as airline,"
				+ " f.client_id as clientId,"
				+ " f.client_business_code as clientBusinessCode,"
				+ " f.protocol_date_start as protocolDateStart,"
				+ " f.protocol_date_end as protocolDateEnd,"
				+ " sum(f.total_Amount) as totalNormalSale,"
				+ " sum(f.vendor_Total_Amount) as vendorTotalAmount,"
				+ " sum(f.ticket_Price) as totalTicketPrice,"
				+ " sum(f.tax) as totalTax "			
				+ " from fare_and_order_tripartite_policy f where f.enabled_Flag = 'Y' and f.ticket_status ='TICKET_STATUS_NORMAL' ");	
		sqlRefund.append("select f.airline as airline,"
				+ " f.client_id as clientId,"
				+ " f.client_business_code as clientBusinessCode,"
				+ " sum(f.total_Amount) as totalRefundSale,"
				+ " sum(f.refund_Price) as totalRefundPrice "			
				+ " from fare_and_order_tripartite_policy f where f.enabled_Flag = 'Y' and f.ticket_status ='TICKET_STATUS_REFUND' ");
		sqlInvalid.append("select f.airline as airline,"
				+ " f.client_id as clientId,"
				+ " f.client_business_code as clientBusinessCode,"
				+ " sum(f.total_Amount) as totalInvalidSale,"
				+ " sum(f.refund_Price) as totalInvalidActualAmount "			
				+ " from fare_and_order_tripartite_policy f where f.enabled_Flag = 'Y' and f.ticket_status ='TICKET_STATUS_INVALID' ");
		// 筛选条件
		//预定时间必须在协议期内
		sqlCondition.append("and f.book_date >= f.protocol_date_start ");
		sqlCondition.append("and f.book_date < (f.protocol_date_end + 1000000) ");
		
		if (ObjectUtil.hasText(fare.getOperatoringTimeStartStr())) {
			sqlCondition.append(" and f.operatoring_Time >= :operatoringTimeStart");
			params.put("operatoringTimeStart",
					DateUtil.toLongDate(fare.getOperatoringTimeStartStr(), DateUtil.yyyy_MM_dd));
		}
		if (ObjectUtil.hasText(fare.getOperatoringTimeEndStr())) {
			sqlCondition.append(" and f.operatoring_Time <= :operatoringTimeEnd");
			params.put("operatoringTimeEnd", DateUtil.toLongDate(fare.getOperatoringTimeEndStr(), DateUtil.yyyy_MM_dd));
		}
		if(ObjectUtil.hasText(order.getDepartureDateStartStr())){
			sqlCondition.append(" and f.departure_Date >= :departureDateStart");
			params.put("departureDateStart", DateUtil.toLongDate(order.getDepartureDateStartStr(), DateUtil.yyyy_MM_dd));					
		}
		if(ObjectUtil.hasText(order.getDepartureDateEndStr())){
			sqlCondition.append(" and f.departure_Date >= :departureDateEnd");
			params.put("departureDateEnd", DateUtil.toLongDate(order.getDepartureDateEndStr(), DateUtil.yyyy_MM_dd));
		}
		if(ObjectUtil.hasText(order.getAirline())){
			sqlCondition.append(" and f.airline = :airline ");
			params.put("airline", order.getAirline());
		}
		if(order.getClientId() != null){
			sqlCondition.append(" and f.client_id = :clientId ");
			params.put("clientId", order.getClientId());
		}
		sqlCondition.append(" group by f.airline,f.client_id,f.client_business_code,f.ticket_status");
	
		sqlNormal.append(sqlCondition);
		sqlRefund.append(sqlCondition);
		sqlInvalid.append(sqlCondition);
		sql.append(" select normal.*,refund.totalRefundPrice,"//
				+ " invalid.totalInvalidActualAmount from "//
				+ " (" + sqlNormal + " ) as normal left join "//
				+ " (" + sqlRefund + " ) as refund on "//
				+ " normal.airline = refund.airline and "//
				+ " normal.clientId = refund.clientId and "//
				+ " normal.clientBusinessCode = refund.clientBusinessCode left join "//
				+ " (" + sqlInvalid + ") as invalid on "//
				+ " normal.airline = invalid.airline and "//
				+ " normal.clientId = invalid.clientId and "
				+ " normal.clientBusinessCode = invalid.clientBusinessCode ");
		return this.findSqlList(sql.toString(), params);
		
	}

	@SuppressWarnings("rawtypes")
	public List<Map> findByCond(ContextInfo context, TripartiteReport cond, Map<String, String> groupByMap) {
		
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		StringBuilder sqlNormal = new StringBuilder();// 正常票SQL段
		StringBuilder sqlCondition = new StringBuilder(); // 条件SQL段
		StringBuilder sqlGroupBy = new StringBuilder(); // 分组条件
		if(!(groupByMap == null || groupByMap.isEmpty())){
			for (Map.Entry<String, String> obj : groupByMap.entrySet()) {
				sqlGroupBy.append("f."+obj.getKey()+" as "+obj.getValue()+",");
			}
		}
		sqlNormal.append("select f.airline as airline,"
				+ " f.tripartite_policy_id as tripartitePolicyId,"
				+	sqlGroupBy
				+ " sum(f.total_Amount) as totalAmount,"
				+ " sum(f.vendor_Total_Amount) as vendorTotalAmount,"
				+ " sum(f.ticket_Price) as totalTicketPrice,"
				+ " sum(f.refund_Price) as totalRefundPrice,"
				+ " sum(f.refund_Price) as totalInvalidActualAmount,"
				+ " sum(f.tax) as totalTax "			
				+ " from fare_and_order_tripartite_policy f where f.enabled_Flag = 'Y' ");	
		// 筛选条件
		//预定时间必须在协议期内
		sqlCondition.append("and f.book_date >= f.protocol_date_start ");
		sqlCondition.append("and f.book_date < (f.protocol_date_end + 1000000) ");
		
		if (ObjectUtil.hasText(cond.getOperatoringTimeStartStr())) {
			sqlCondition.append(" and f.operatoring_Time >= :operatoringTimeStart");
			params.put("operatoringTimeStart",
					DateUtil.toLongDate(cond.getOperatoringTimeStartStr(), DateUtil.yyyy_MM_dd));
		}
		if (ObjectUtil.hasText(cond.getOperatoringTimeEndStr())) {
			sqlCondition.append(" and f.operatoring_Time <= :operatoringTimeEnd");
			params.put("operatoringTimeEnd", DateUtil.toLongDate(cond.getOperatoringTimeEndStr(), DateUtil.yyyy_MM_dd));
		}
		if(ObjectUtil.hasText(cond.getDepartureDateStartStr())){
			sqlCondition.append(" and f.departure_Date >= :departureDateStart");
			params.put("departureDateStart", DateUtil.toLongDate(cond.getDepartureDateStartStr(), DateUtil.yyyy_MM_dd));					
		}
		if(ObjectUtil.hasText(cond.getDepartureDateEndStr())){
			sqlCondition.append(" and f.departure_Date >= :departureDateEnd");
			params.put("departureDateEnd", DateUtil.toLongDate(cond.getDepartureDateEndStr(), DateUtil.yyyy_MM_dd));
		}
		if(ObjectUtil.hasText(cond.getAirline())){
			sqlCondition.append(" and f.airline = :airline ");
			params.put("airline", cond.getAirline());
		}else{
			sqlCondition.append(" and f.airline != :airline ");
			params.put("airline", "CX");
		}
		if(cond.getClientId() != null){
			sqlCondition.append(" and f.client_id = :clientId ");
			params.put("clientId", cond.getClientId());
		}
		
		// 分组条件f.client_id,f.client_business_code,f.task,
		sqlCondition.append(" group by f.airline,f.tripartite_policy_id,");
		if(!(groupByMap == null || groupByMap.isEmpty())){
			for (Map.Entry<String, String> obj : groupByMap.entrySet()) {
				sqlCondition.append(" f." + obj.getKey() + ",");
			}
		}
		sqlNormal.append(sqlCondition.substring(0, sqlCondition.length()-1));

		sql.append("select c.* from ("+sqlNormal+") as c");
		return this.findSqlList(sql.toString(), params);
		
	}
	
	@SuppressWarnings("rawtypes")
	public Pagination<Map> wangdian(ContextInfo context, IntairFare fare, IntairOrder order,int pageIndex, int pageSize) {
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql= new StringBuilder();
		StringBuilder sqlCount= new StringBuilder();
		StringBuilder sqlNormal = new StringBuilder();//正常票SQL段
		StringBuilder sqlRefund = new StringBuilder();//退票SQL段
		StringBuilder sqlInvalid = new StringBuilder();//废票SQL段
		StringBuilder sqlCondition= new StringBuilder(); //条件SQL段
		
		sqlNormal.append("select f.eshop_Id as eshopId,"
				+ " count(1) as totalNormalTicket,"
				+ " sum(f.total_Amount) as totalAmount,"
				+ " sum(f.vendor_Total_Amount) as vendorTotalAmount,"
				+ " sum(f.ticket_Price) as totalTicketPrice,"
				+ " sum(f.tax) as totalTax "			
				+ " from Intair_Fare f where f.enabled_Flag = 'Y' and f.ticket_status ='TICKET_STATUS_NORMAL' ");	
		sqlRefund.append("select f.eshop_Id as eshopId,"
				+ " count(1) as totalRefundTicket,"
				+ " sum(f.refund_Price) as totalRefundPrice,"
				+ " sum(f.vendor_Refund_Price) as totalVendorRefundPrice"			
				+ " from Intair_Fare f where f.enabled_Flag = 'Y' and f.ticket_status ='TICKET_STATUS_REFUND' ");
		sqlInvalid.append("select f.eshop_Id as eshopId,"
				+ " count(1) as totalInvalidTicket,"
				+ " sum(f.refund_Price) as totalInvalidActualAmount,"
				+ " sum(f.abandon_Price) as totalAbandonPrice "				
				+ " from Intair_Fare f where f.enabled_Flag = 'Y' and f.ticket_status ='TICKET_STATUS_INVALID' ");
		
		if(ObjectUtil.hasText(fare.getOperatoringTimeStartStr())){
			sqlCondition.append(" and f.operatoring_Time >= :operatoringTimeStart");
			params.put("operatoringTimeStart", DateUtil.toLongDate(fare.getOperatoringTimeStartStr(), DateUtil.yyyy_MM_dd));
		}
		if(ObjectUtil.hasText(fare.getOperatoringTimeEndStr())){
			sqlCondition.append(" and f.operatoring_Time <= :operatoringTimeEnd");
			params.put("operatoringTimeEnd", DateUtil.toLongDate(fare.getOperatoringTimeEndStr(), DateUtil.yyyy_MM_dd));
		}
		if(fare.getEshopId() != null){
			sqlCondition.append(" and f.eshop_Id =:eshopId ");
			params.put("eshopId", fare.getEshopId());			
		}
		sqlCondition.append(" and f.order_Id in "
				+ " (select  o.order_Id from Intair_Order o where o.enabled_Flag = 'Y' ");
		if(ObjectUtil.hasText(order.getPlatform())){
			sqlCondition.append(" and o.platform = :platform ");
			params.put("platform", order.getPlatform());
		}
		if(ObjectUtil.hasText(order.getDepartureDateStartStr())){
			sqlCondition.append(" and o.departure_Date >= :departureDateStart");
			params.put("departureDateStart", DateUtil.toLongDate(order.getDepartureDateStartStr(), DateUtil.yyyy_MM_dd));					
		}
		if(ObjectUtil.hasText(order.getDepartureDateEndStr())){
			sqlCondition.append(" and o.departure_Date >= :departureDateEnd");
			params.put("departureDateEnd", DateUtil.toLongDate(order.getDepartureDateEndStr(), DateUtil.yyyy_MM_dd));
		}
		if(ObjectUtil.hasText(order.getAirline())){
			sqlCondition.append(" and o.airline =:airline");
			params.put("airline", order.getAirline());
		}
		sqlCondition.append(" ) ");
		sqlCondition.append(" group by f.eshop_Id,f.ticket_status");
		
		sqlNormal.append(sqlCondition);
		sqlRefund.append(sqlCondition);
		sqlInvalid.append(sqlCondition); 
		sql.append(" select A.*,B.totalRefundTicket,B.totalRefundPrice,B.totalVendorRefundPrice,"
				+ " C.totalInvalidTicket,C.totalInvalidActualAmount,C.totalAbandonPrice from "
				+ " ("+ sqlNormal + " ) as A left join "
				+ " ("+ sqlRefund+" ) as B on A.eshopId = B.eshopId left join "
				+ " ("+ sqlInvalid+") as C on A.eshopId = C.eshopId");
		sqlCount.append("select count(1) from ("+sql+") s"); //计算总记录数
		return this.findSqlPagination(sql.toString(), sqlCount, params, pageIndex, pageSize);
	}
	
	
	public Pagination<IntairFare> findByFareAndOrder(ContextInfo context, IntairFare fare, IntairOrder order, int pageIndex, int pageSize) {
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		sql.append(" from  IntairFare  c  where c.enabledFlag = 'Y' ");
		sql.append(" and exists (select o.orderId from IntairOrder o where o.orderId = c.orderId and o.enabledFlag = 'Y' ");
		if(ObjectUtil.hasText(order.getDepartureDateStartStr())){
			sql.append(" and o.departureDate >= :departureDateStart");
			params.put("departureDateStart", DateUtil.toLongDate(order.getDepartureDateStartStr(), DateUtil.yyyy_MM_dd));					
		}
		if(ObjectUtil.hasText(order.getDepartureDateEndStr())){
			sql.append(" and o.departureDate >= :departureDateEnd");
			params.put("departureDateEnd", DateUtil.toLongDate(order.getDepartureDateEndStr(), DateUtil.yyyy_MM_dd));
		}
		//根据订票员ID查询
		if(order.getBookOperatorId() != null){
			sql.append(" and o.operatorId = :operatorId ");
			params.put("operatorId", order.getBookOperatorId());
		}
		if(order.getClientId() != null){
			sql.append(" and o.clientId = :clientId ");
			params.put("clientId", order.getClientId());
		}
		if(ObjectUtil.hasText(order.getMemo())){
			sql.append(" and o.memo like :memo");
			params.put("memo", "%"+order.getMemo()+"%");
		}
		sql.append(" ) ");		
		if(ObjectUtil.hasText(fare.getOperatoringTimeStartStr())){
			sql.append(" and c.operatoringTime >= :operatoringTimeStart");
			params.put("operatoringTimeStart", DateUtil.toLongDate(fare.getOperatoringTimeStartStr(), DateUtil.yyyy_MM_dd));
		}
		if(ObjectUtil.hasText(fare.getOperatoringTimeEndStr())){
			sql.append(" and c.operatoringTime <= :operatoringTimeEnd");
			params.put("operatoringTimeEnd", DateUtil.toLongDate(fare.getOperatoringTimeEndStr(), DateUtil.yyyy_MM_dd));
		}
		if(fare.getDrawOperatorId() !=null){
			sql.append(" and c.operatorId = :operatorId");
			params.put("operatorId", fare.getDrawOperatorId());
		}
		if(ObjectUtil.hasText(fare.getTicketStatus())){
			sql.append(" and c.ticketStatus = :ticketStatus");
			params.put("ticketStatus", fare.getTicketStatus());
		}
		sql.append(" order by c.lastUpdateDate desc ");
		return this.findPagination(sql.toString(), params, pageIndex, pageSize);
	}
	
	

	public IntairFare findByOrderId(ContextInfo context, Long orderId) {
		if (orderId == null) {
			return null;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		sql.append(" from IntairFare c where c.enabledFlag = 'Y' ");
		sql.append(" and c.orderId = :orderId ");
		params.put("orderId", orderId);
		return this.get(sql.toString(), params);
	}
	
	public IntairFare findByPassengerId(ContextInfo contextInfo, Long passengerId) {
		if (passengerId == null) {
			return null;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		sql.append(" from IntairFare c where c.enabledFlag = 'Y' ");
		sql.append(" and c.passengerId = :passengerId ");
		params.put("passengerId", passengerId);
		return this.get(sql.toString(), params);
	}
	public List<IntairFare> findAll(ContextInfo contextInfo) {
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		sql.append(" from  IntairFare  c  where c.enabledFlag = 'Y' ");
		sql.append(" order by c.lastUpdateDate desc ");
		return this.findList(sql.toString(), params);
	}
	
}
